<?php

declare(strict_types=1);

namespace BitWasp\Bitcoin\Tests\Block;

use BitWasp\Bitcoin\Block\BlockHeaderFactory;
use BitWasp\Bitcoin\Block\BlockHeaderInterface;
use BitWasp\Bitcoin\Tests\AbstractTestCase;

class BlockHeaderBip9Test extends AbstractTestCase
{
    public function getHasBip9PrefixFixtures()
    {
        $vectors = [];
        foreach ([
            [true, "0000002006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f6bacbc493f2405964b88419a32290df01cd773001d1969e3efbf5944b7b6a21424bd3f59ffff7f2002000000"],
            [false, "010000000508085c47cc849eb80ea905cc7800a3be674ffc57263cf210c59d8d00000000112ba175a1e04b14ba9e7ea5f76ab640affeef5ec98173ac9799a852fa39add320cd6649ffff001d1e2de565"],
            [false, "0100000050120119172a610421a6c3011dd330d9df07b63616c2cc1f1cd00200000000006657a9252aacd5c0b2940996ecff952228c3067cc38d4885efb5a4ac4247e9f337221b4d4c86041b0f2b5710"],
            [false, "010000006fd2c5a8fac33dbe89bb2a2947a73eed2afc3b1d4f886942df08000000000000b152eca4364850f3424c7ac2b337d606c5ca0a3f96f1554f8db33d2f6f130bbed325a04e4b6d0b1a85790e6b"],
            [false, "0200000015a20d97f5a65e130e08f2b254f97f65b96173a7057aef0da203000000000000887e309c02ebdddbd0f3faff78f868d61b1c4cff2a25e5b3c9d90ff501818fa0e7965d508bdb051a40d8d8f7"],
            [false, "020000005a88b97d846a6c9ddd4a21d31f53a620437f629db83930622d00000000000000f27fed25be76bbe37436c33cf81a3f9cac7ce179faf50c73893843c981974ab3056d6051be2f021a579b633d"],
            [false, "02000000028f2cb75e0b6b2bcaba83efa34cb6af4a7bc04e882de8c2090000000000000023d7fee87f54bfb980f383b80742ac060bb5294ff9cb82d159caa8acaf1eec1647f9fc51f2db721961769100"],
            [false, "020000004b53ca06287dc3c1820de25fab835cd9698ee5fb808893570600000000000000ee20ba1618240e6448f7401b1eb6b4ac676591047be223cd899f6fb6462e029e02ed8752f3670819620daf8f"],
            [false, "020000007ef055e1674d2e6551dba41cd214debbee34aeb544c7ec670000000000000000d3998963f80c5bab43fe8c26228e98d030edf4dcbe48a666f5c39e2d7a885c9102c86d536c890019593a470d"],
            [false, "020000005748ffab7facabb9445f04cf7b504ada65c00d92900fe20300000000000000008fd235e2ee95cc968ed06be3f722a9fec1d947f45928c175a815c6729751975a6930665430c31b18b414e3df"],
            [false, "0200000030bd6b2df98c2085b489dda6aac0c6d077109af8645604020000000000000000620aa373a73b753cd47a581969dd233e3c6a92033438f51b6067a29ca42fe79c6acb1955f288171880944fd5"],
            [false, "030000005d5e2508f13fb5f8afef709e908841da9c3af2cb200d6307000000000000000091b813be139ade2ce2f3eb97ee31948b38e226123379c237ead7ef6fda2e50d32181cf5504dd1418cb83d8cf"],
            [false, "0400000039fa821848781f027a2e6dfabbf6bda920d9ae61b63400030000000000000000ecae536a304042e3154be0e3e9a8220e5568c3433a9ab49ac4cbb74f8df8e8b0cc2acf569fb9061806652c27"],
            [true, "00000020cf60c99cd0d14181556d6db3238a6ca4eed31119c35b03030000000000000000fa0f9ea6c329b99b6d17576b73bc781267e566430aee747205b0acbca5238302552a8157fd260518b432bd82"],
            [true, "00000020daf37bb5b5d98651b1c65cdd1c34ce79ab5b48f0354a4c020000000000000000251952424d22534025140c2aabbda76b9bd60d103f49516408bd577df58c50ff9122895847cc02187d842db1"],
            [true, "010000206c89722b9ef6d8d47068b42727de1e3f606c84af5c1fbf02000000000000000087186972574ef0a4abd6049a6d132ae2dbddb1c747570f5f211d5fcfea81d88ee7eb7a57d63f05187483ee90"],
        ] as $fixture) {
            list ($hasBip9, $hex) = $fixture;
            $header = BlockHeaderFactory::fromHex($hex);
            $vectors[] = [$hasBip9, $header];
        }
        return $vectors;
    }

    /**
     * @param int $shouldHaveBip9Prefix
     * @param BlockHeaderInterface $header
     * @dataProvider getHasBip9PrefixFixtures
     */
    public function testHasBip9Prefix($shouldHaveBip9Prefix, BlockHeaderInterface $header)
    {
        $this->assertEquals($shouldHaveBip9Prefix, $header->hasBip9Prefix());
    }
}
